<?php 
class CommonController extends Controller{

	public function __init(){
		parent::__init();
		$this->ifLogin();
		header('Content-type: text/html;charset=utf-8');
		
	}


	public function ifLogin(){
		if(!isset($_SESSION['uid']) && !isset($_SESSION['uname'])){
			session('url',__URL__);
		}
	}
	
    public function getFather($data,$cid){
        $temp = array();
        foreach ($data as $v) {
            if($v['cid']==$cid){
                $temp[] = $v;
                $temp = array_merge($temp,$this->getFather($data, $v['pid']));
            }
        }
        return $temp;
    }	
	public function topCate(){
		$topCate = K('Category')->where('pid=0')->limit(8)->all();
        // 获得顶级分类的子分类
        foreach ($topCate as $k => $v) {
           $topCate[$k]['son'] = K('Category')->where('pid=' . $v['cid'])->limit(8)->all();
           foreach ($topCate[$k]['son'] as $key => $value) {
              $topCate[$k]['son'][$key]['son'] = K('Category')->where('pid=' . $value['cid'])->all();
           }
        }
        // p($cate);
    	$this->assign('topCate',$topCate);
		

//		p($allcate);
	}

	
	
}














 ?>